//
//  GFScanView.m
//  GoFactory
//
//  Created by wtb on 2017/12/19.
//  Copyright © 2017年 KQZK. All rights reserved.
//

#import "GFScanView.h"
#import "KqScreenUtil.h"
#import "KqTool.h"

@implementation GFScanView

-(instancetype)init
{
    if (self = [super init]) {
        [self bottomScanView];
    }
    return self;
}

-(void)bottomScanView
{
    UIButton *anyQcode = [UIButton buttonWithType:UIButtonTypeCustom];
    anyQcode.tag = 102;
    [anyQcode setImage:[KqTool tz_imageNamedFromMyBundle:@"scanheighlight"]
              forState:UIControlStateNormal];
    [anyQcode addTarget:self action:@selector(scanAnyQcan)
       forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:anyQcode];
    
    
    UILabel *anyQcodeLabel = [[UILabel alloc] init];
    anyQcodeLabel.tag = 104;
    anyQcodeLabel.text = @"扫码";
    anyQcodeLabel.textColor = [UIColor colorWithRed:58/255.0 green:85/255.0 blue:155/255.0 alpha:1];
    anyQcodeLabel.textAlignment = NSTextAlignmentCenter;
    anyQcodeLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:anyQcodeLabel];
    CGFloat fontHeight = [anyQcodeLabel.text boundingRectWithSize:CGSizeMake(RateWidth(40), ScreenHight()) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size.height;
    
    CGFloat space = (RateHeight(90) - RateWidth(40) - fontHeight)/2.0;
    anyQcode.frame = CGRectMake(RateWidth(104), space, RateWidth(40), RateWidth(40));
    anyQcodeLabel.frame = CGRectMake(RateWidth(104), CGRectGetMaxY(anyQcode.frame)+RateHeight(5), RateWidth(40), 16);
    
    UIButton *boxQcode = [UIButton buttonWithType:UIButtonTypeCustom];
    boxQcode.tag = 103;
    [boxQcode setImage:[KqTool tz_imageNamedFromMyBundle:@"scanboxgray"]
              forState:UIControlStateNormal];
    [boxQcode addTarget:self action:@selector(scanBoxQcan)
       forControlEvents:UIControlEventTouchUpInside];
    boxQcode.frame = CGRectMake(ScreenWidth()-RateWidth(104), CGRectGetMaxY(anyQcodeLabel.frame), RateWidth(40), RateWidth(40));
    [self addSubview:boxQcode];
    
    UILabel *boxQcodeLabel = [[UILabel alloc] init];
    boxQcodeLabel.text = @"BOX";
    boxQcodeLabel.tag = 105;
    boxQcodeLabel.textColor = [UIColor colorWithRed:155/255.0 green:155/255.0 blue:155/255.0 alpha:1];
    boxQcodeLabel.font = [UIFont systemFontOfSize:14];
    boxQcodeLabel.textAlignment = NSTextAlignmentCenter;
    boxQcodeLabel.frame = CGRectMake(ScreenWidth()-RateWidth(104), CGRectGetMaxY(anyQcode.frame)+RateHeight(5), RateWidth(40), 16);
    [self addSubview:boxQcodeLabel];
    
    UIControl *anyQcodeControl = [[UIControl alloc] init];
    [anyQcodeControl addTarget:self action:@selector(scanAnyQcan) forControlEvents:UIControlEventTouchUpInside];
    anyQcodeControl.frame = CGRectMake(0, space, ScreenWidth()/2, RateHeight(90));
    [self addSubview:anyQcodeControl];
    
    UIControl *boxQcodeControl = [[UIControl alloc] init];
    [boxQcodeControl addTarget:self action:@selector(scanBoxQcan) forControlEvents:UIControlEventTouchUpInside];
    boxQcodeControl.frame = CGRectMake(ScreenWidth()/2, space, anyQcodeControl.bounds.size.width, anyQcodeControl.bounds.size.height);
    [self addSubview:boxQcodeControl];
}

-(void)scanAnyQcan
{
    UIButton *btn = [self viewWithTag:102];
    UIButton *boxBtn = [self viewWithTag:103];
    UILabel *anyLabel = [self viewWithTag:104];
    UILabel *boxLabel = [self viewWithTag:105];
    [btn setImage:[KqTool tz_imageNamedFromMyBundle:@"scanheighlight"]
         forState:UIControlStateNormal];
    anyLabel.textColor = [UIColor colorWithRed:58/255.0 green:85/255.0 blue:155/255.0 alpha:1];
    [boxBtn setImage:[KqTool tz_imageNamedFromMyBundle:@"scanboxgray"]
            forState:UIControlStateNormal];
    boxLabel.textColor = [UIColor colorWithRed:155/255.0 green:155/255.0 blue:155/255.0 alpha:1];
    [self.delegate clickAnyScan];
}

-(void)scanBoxQcan
{
    UIButton *anyBtn = [self viewWithTag:102];
    UIButton *btn = [self viewWithTag:103];
    UILabel *anyLabel = [self viewWithTag:104];
    UILabel *boxLabel = [self viewWithTag:105];
    
    [anyBtn setImage:[KqTool tz_imageNamedFromMyBundle:@"scan"]
            forState:UIControlStateNormal];
    anyLabel.textColor = [UIColor colorWithRed:155/255.0 green:155/255.0 blue:155/255.0 alpha:1];
    [btn setImage:[KqTool tz_imageNamedFromMyBundle:@"scanbox"]
         forState:UIControlStateNormal];
    boxLabel.textColor = [UIColor colorWithRed:58/255.0 green:85/255.0 blue:155/255.0 alpha:1];
    [self.delegate clickBoxScan];
}
@end
